/**
 * Created by mapbar_front on 2019/8/9.
 */
import React,{Component} from 'react';
var createReactClass = require('create-react-class');

var setIntervalMixin = {
    componentWillMount:function(){
        this.intervals = [];
    },
    setInterval:function(){
        this.intervals.push(setInterval.apply(null,arguments));
    },
    componentWillUnmout: function(){
        this.intervals.forEach(clearInterval);
    }

}

var NoES6 = createReactClass({
    mixins:[setIntervalMixin], //使用mixin
    getDefaultProps: function(){
        return {
            name: 'xiaoxiao'
        }
    },
    getInitialState:function(){
        return {
            count: this.props.initialCount,
            seconds: 0,
        }
    },
    componentDidMount:function(){
        this.setInterval(this.trick,1000);
    },
    trick: function(){
        this.setState({
            seconds: this.state.seconds+1,
        })
    },
    handleClick: function(){
        console.log(this.state.count);
    },
    render: function(){
        return  <div>
                    <h1>Hello,{this.props.name}</h1>
                    <h2>num:{this.state.count}</h2>
                    <button onClick={this.handleClick}>点击</button>
                    <div>
                        React has been running for {this.state.seconds} seconds.
                    </div>
                    <h1>
                        123
                    </h1>
                </div>
    }
})

// NoES6.defaultProps = {
//     name:'xiao',
// }

export default NoES6;
